<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class LableCategory extends Model
{
    use HasFactory;
    use PimpableTrait;

    /**
     * 可执行搜索的字段
     */
    public $searchable = [
        'id',
        'system_admin_id',
        'name',
        'type',
    ];

    /**
     * 可批量赋值的字段
     */
    public $fillable = [
        'pid',
        'system_admin_id',
        'name',
        'sort',
        'type'
    ];

    /**
     * 进行排序的字段
     */
    public $sortable =[
        'pid',
        'sort'
    ];

    /**
     *默认倒叙的字段
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 标签分类关联的用户表 创建该分类标签的用户
     */
    protected function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    /**
     * 标签分类表对应的标签表
     */
    protected function userLabel(){
        return $this->hasMany(UserLabel::class,'label_category_id','id');
    }
}
